<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Admin\Role;

class RoleController extends Controller
{
    public function getList(Request $request)
    {
        $pageSize = $request['pageSize'];

        $roleModel = new Role;
        $data = $roleModel->getList($pageSize);

        return $data;
    }

    public function handle(Request $request)
    {
        $data = [];
        $data['id'] = $request['id'];
        $data['store_id'] = empty($request['store_id']) ? 0 : $request['store_id'];
        $data['title'] = $request['title'];
        $data['describe'] = $request['describe'];
        $data['status'] = $request['status'];
        $data['menu_ids'] = empty($request['menu_ids']) ? '' : $request['menu_ids'];
        $data['half_menu_ids'] = empty($request['half_menu_ids']) ? '' : $request['half_menu_ids'];
        $data['rule_ids'] = empty($request['rule_ids']) ? '' : $request['rule_ids'];

        $roleModel = new Role;
        $result = $roleModel->handle($data);

        return $result;
    }

    public function getMenuNode()
    {
        $roleModel = new Role;
        $result = $roleModel->getAllMenuNodes();

        return $result;
    }

    public function getStore()
    {
        $roleModel = new Role;
        $result = $roleModel->getStore();

        return $result;
    }

    public function getRoles()
    {
        $roleModel = new Role;
        $result = $roleModel->getRoles();

        return $result;
    }

    public function delete(Request $request)
    {
        $id = $request['id'];
        $roleModel = new Role;
        $result = $roleModel->deleteAction($id);

        return $result;
    }
}
